package com.onlyxiahui.common.action.description.handler.impl.validate;

import java.lang.annotation.Annotation;
import java.util.List;

import org.springframework.core.MethodParameter;

import com.onlyxiahui.common.action.description.DocumentContext;
import com.onlyxiahui.common.action.description.bean.PropertyData;
import com.onlyxiahui.common.action.description.box.data.ValidationData;
import com.onlyxiahui.common.action.description.handler.ParameterValidateHandler;

/**
 * Description <br>
 * Date 2020-04-05 13:18:04<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class ValidationParameterValidateHandler implements ParameterValidateHandler {

	@Override
	public boolean support(DocumentContext context, PropertyData propertyData, MethodParameter parameter) {
		return true;
	}

	@Override
	public void handle(DocumentContext context, PropertyData propertyData, MethodParameter parameter) {
		this.get(context, propertyData, parameter);
	}

	public void get(DocumentContext context, PropertyData propertyData, MethodParameter parameter) {
		List<ValidationData> validationDatas = context.getValidationDataBox().allList();
		for (ValidationData vd : validationDatas) {
			set(context, propertyData, vd, parameter);
		}
	}

	public void set(DocumentContext context, PropertyData propertyData, ValidationData vd, MethodParameter parameter) {
		if (null != vd) {
			Annotation[] as = parameter.getParameterAnnotations();
			ValidationBase.set(vd, propertyData, as);
		}
	}
}
